package cn.edu.hy.demo09.service;

import cn.edu.hy.demo09.entity.Pay;
import cn.edu.hy.demo09.entity.Product;
import cn.edu.hy.demo09.mapper.PayMapper;
import cn.edu.hy.demo09.mapper.ProductMapper;
import com.github.monee1988.mybatis.entity.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.UUID;

@Service
public class ProductService {

    @Resource
    private ProductMapper productMapper;
    @Resource
    private PayMapper payMapper;

    public Page<Product> findList(Product product,Page<Product> page) {
        product.setPage(page);
        page.setList(productMapper.findList(product));
        return page;
    }

    public boolean udpateProductInfo(Product product) {
        product.setInventory(50);
        productMapper.udpateProductInfo(product);
//        System.out.println(1/0);
        Pay pay = new Pay();
        pay.setId(UUID.randomUUID().toString());
        pay.setBuyer("test");
        pay.setCount(50);
        pay.setProduct(product);
        pay.setTotalMoney(product.getPrice()*50);
        payMapper.savePay(pay);
        return true;
    }
}
